package com.hgc.boot01.controller;

import com.hgc.boot01.pojo.ClassInfo;
import com.hgc.boot01.service.ClassInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/class")
public class ClassInfoController {

    @Resource
    private ClassInfoService classInfoService;

    @PostMapping("/add")
    public String addClass(@RequestBody ClassInfo classInfo) {
        boolean result = classInfoService.addClass(classInfo);
        return result ? "新增成功" : "新增失败";
    }

    @DeleteMapping("/delete/{classId}")
    public String deleteClass(@PathVariable Integer classId) {
        boolean result = classInfoService.deleteClass(classId);
        return result ? "删除成功" : "删除失败";
    }

    @PutMapping("/update")
    public String updateClass(@RequestBody ClassInfo classInfo) {
        boolean result = classInfoService.updateClass(classInfo);
        return result ? "更新成功" : "更新失败";
    }

    @GetMapping("/get/{classId}")
    public ClassInfo getClassById(@PathVariable Integer classId) {
        return classInfoService.getClassById(classId);
    }

    @GetMapping("/list")
    public List<ClassInfo> listAllClasses() {
        return classInfoService.listAllClasses();
    }
}